package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.util.FileUtil;
import com.atguigu.tingshu.common.result.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@Tag(name = "上传管理接口")
@RestController
@RequestMapping("api/album")
public class FileUploadApiController {

    @Autowired
    private FileUtil fileUtil;



    /**
     * 专辑封面上传
     * @param file
     * @return
     */
    @PostMapping("/fileUpload")
    public Result fileUpload(@RequestParam MultipartFile file){
        return Result.ok(fileUtil.fileUpload(file));
    }

    /**
     * 删除专辑封面
     * @param fileName
     */
    @DeleteMapping("/deleteFile")
    public void deleteFile(@RequestParam String fileName){
        fileUtil.deleteFile(fileName);
    }

    /**
     * 下载
     * @param fileName
     * @param localPath
     * @return
     */
    @GetMapping("/fileDownload")
    public Result fileDownload(@RequestParam String fileName,@RequestParam String localPath){
        // 路径
        fileUtil.fileDownload(fileName,localPath);
        return Result.ok();
    }


}
